package kjd;

import static org.junit.Assert.assertTrue;
import kjd.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that GunAryos turns after
 * wall impact. Based on file provided by Philip Johnson. Modified for GunAryos and kjd package.
 * 
 * @author Philip Johnson, Kendyll Doi
 * 
 */
public class TestGunAryosTurnsAtWall extends RobotTestBed {
  boolean afterHitWall = false; // true if it is the turn after robot hits wall.
  double impactAngle; // holds the angle at which the robot hit the wall.
  double afterImpactAngle; // holds the angle in the turn after robot hit the wall.

  /**
   * Specifies that SittingDuck and GunAryos are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,kjd.GunAryos";
  }

  /**
   * This test runs for 2 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 2;
  }

  /**
   * The actual test, which asserts that GunAryos turns after it hits a wall.
   * 
   * @param event Details about the ended turn.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    // test if this is the turn after impacting a wall.
    if (afterHitWall) {
      // gets the heading of the robot into the wall.
      afterImpactAngle = robot.getBodyHeading();
      // resets afterHitWall since we are past hitting the wall and checking.
      afterHitWall = false;
      // Checks to make sure the that the angle the robot hit the wall is not the same as it is
      // after.
      assertTrue("Checks if robot turns", afterImpactAngle != impactAngle);
    }
    // Checks if robot hit the wall this turn
    if (robot.getState().isHitWall()) {
      // stores the afterHitWall a true value to check rotation next turn.
      afterHitWall = true;
      // stores impactAngle for comparison next turn.
      impactAngle = robot.getBodyHeading();
    }
  }
}
